<?php 


require "../common/Curl.php";

/**
 *	https://open.esign.cn/doc/detail?id=opendoc%2Fpaas_api%2Fsgv49u&namespace=opendoc%2Fpaas_api
 * 	电子签名SaaS API非标版
 * 	印章服务 辅助api列表----接口顺序排列封装
 *  使用请求签名鉴权方式
 *  下一个------------------ 文件管理file.php
 */


//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


/**
 * [setDefault 设置个人默认印章]
 * @param [type] $accountId [个人签署账号id，通过创建个人签署账号接口获取]
 * @param [type] $sealId    [个人印章id]
 * @param [json] return     [返回结果]
 */
function setDefaultPerson($accountId,$sealId,$appId,$secret,$url){
	$urlss = $url."/v1/accounts/".$accountId."/seals/".$sealId."/setDefault";
	$head_url = "/v1/accounts/".$accountId."/seals/".$sealId."/setDefault";
	$data = [];
	$res = json_encode($data);
    $header = getHeader($data,"PUT",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="PUT",$urlss,$header,$res);
    return $result;
}
// $accountId = "5539bd029e4e45f4b2095aacbcf1ea19";
// $sealId = 'ee3ae75a-4333-4295-8de4-b352ea37a258';
// $a = setDefaultPerson($accountId,$sealId,$appId,$secret,$url);
// var_dump($a);die;


//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [setDefault 设置机构默认印章]
 * @param [type] $accountId [个人签署账号id，通过创建个人签署账号接口获取]
 * @param [type] $sealId    [个人印章id]
 * @return [json]           [返回结果]
 */
function setDefaultOrgan($orgId,$sealId,$appId,$secret,$url){
	$urlss = $url."/v1/organizations/".$orgId."/seals/".$sealId."/setDefault";
	$head_url = "/v1/organizations/".$orgId."/seals/".$sealId."/setDefault";
	$data = [];
	$res = json_encode($data);
    $header = getHeader($data,"PUT",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="PUT",$urlss,$header,$res);
    return $result;
}
// $orgId = "6f69dc0a5c8d415aa6a0c7e239a32241";
// $sealId = 'ee3ae75a-4333-4295-8de4-b352ea37a258';
// $a = setDefaultOrgan($orgId,$sealId,$appId,$secret,$url);
// var_dump($a);die;


//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [selectPersonSeals 查询个人印章]
 * @param  [type] $accountId [个人签署账号id]
 * @param  [type] $offset    [分页起始位置]
 * @param  [type] $size      [单页数量]
 * @return [json]            [返回结果列表]
 */
function selectPersonSeals($accountId,$offset,$size,$appId,$secret,$url){
	$urlss = $url."/v1/accounts/".$accountId."/seals?offset=".$offset."&size=".$size."";
	$head_url = "/v1/accounts/".$accountId."/seals?offset=".$offset."&size=".$size."";
	$data = [];
	$res = json_encode($data);
    $header = getHeader($data,"GET",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="GET",$urlss,$header,$res);
    return $result;
}
// $accountId = "5539bd029e4e45f4b2095aacbcf1ea19";
// $offset = 1;
// $size = 10;
// $a = selectPersonSeals($accountId,$offset,$size,$appId,$secret,$url);
// var_dump($a);die;
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [selectPersonSeals 查询机构印章]
 * @param  [type] $orgId [机构id]
 * @param  [type] $offset    [分页起始位置]
 * @param  [type] $size      [单页数量]
 * @return [json]            [返回结果列表]
 */
function selectOrganSeals($orgId,$offset,$size,$appId,$secret,$url){
	$urlss = $url."/v1/accounts/".$orgId."/seals?offset=".$offset."&size=".$size."";
	$head_url = "/v1/accounts/".$orgId."/seals?offset=".$offset."&size=".$size."";
	$data = [];
	$res = json_encode($data);
    $header = getHeader($data,"GET",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="GET",$urlss,$header,$res);
    return $result;
}
// $orgId = "6f69dc0a5c8d415aa6a0c7e239a32241";
// $offset = 1;
// $size = 10;
// $a = selectOrganSeals($orgId,$offset,$size,$appId,$secret,$url);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [deletePersonSeal 删除个人印章 默认印章不可删除]
 * @param [type] $accountId [个人签署账号id，通过创建个人签署账号接口获取]
 * @param [type] $sealId    [个人印章id]
 * @param [json] return     [返回结果]
 */
function deletePersonSeal($accountId,$sealId,$appId,$secret,$url){
	$urlss = $url."/v1/accounts/".$accountId."/seals/".$sealId;
	$head_url = "/v1/accounts/".$accountId."/seals/".$sealId;
	$data = [];
	$res = json_encode($data);
    $header = getHeader($data,"DELETE",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="DELETE",$urlss,$header,$res);
    return $result;
}
// $accountId = "5539bd029e4e45f4b2095aacbcf1ea19";
// $sealId = '58ae3171-6f45-4142-b037-29c0c5a36f1e';
// $a = deletePersonSeal($accountId,$sealId,$appId,$secret,$url);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [deleteOrganSeal 删除机构印章 默认印章不可删除]
 * @param [type] $accountId [机构签署账号id，通过创建个人签署账号接口获取]
 * @param [type] $sealId    [机构印章id]
 * @param [json] return     [返回结果]
 */
function deleteOrganSeal($orgId,$sealId,$appId,$secret,$url){
	$urlss = $url."/v1/organizations/".$orgId."/seals/".$sealId;
	$head_url = "/v1/organizations/".$orgId."/seals/".$sealId;
	$data = [];
	$res = json_encode($data);
    $header = getHeader($data,"DELETE",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="DELETE",$urlss,$header,$res);
    return $result;
}
// $orgId = "6f69dc0a5c8d415aa6a0c7e239a32241";
// $sealId = '5045e9b4-4d82-4780-8e6a-2bc9dd0eec13';
// $a = deleteOrganSeal($orgId,$sealId,$appId,$secret,$url);
// var_dump($a);die;


